<template>
  <van-tabbar class="active_tab">
    <van-tabbar-item
      v-for="(item, index) in tabbars"
      :key="index"
      @click="tab(index, item.name)"
    >
      <img :src="currIndex == index ? item.active : item.normal" />
      <span :style="currIndex == index ? actives : ''">{{ item.title }}</span>
    </van-tabbar-item>
  </van-tabbar>
</template>

<script>
export default {
  name: "tabbar",
  data() {
    return {
      currIndex: 0,
      actives: "color:red",

      tabbars: [
        {
          name: "/home",
          title: "主页",
          normal: require("../assets/image/icon/home.png"),
          active: require("../assets/image/icon/_home.png"),
        },
        {
          name: "/home/notice",
          title: "公告",
          normal: require("../assets/image/icon/_taolunqu.png"),
          active: require("../assets/image/icon/taolunqu.png"),
        },
        {
          name: "/home/sharelife",
          title: "社区",
          normal: require("../assets/image/icon/_shequ.png"),
          active: require("../assets/image/icon/shequ.png"),
        },
        {
          name: "/home/my",
          title: "我的",
          normal: require("../assets/image/icon/my.png"),
          active: require("../assets/image/icon/_my.png"),
        },
      ],
    };
  },
  methods: {
    tab(index, val) {
      this.currIndex = index;
      this.$router.push(val);
    },
  },
};
</script>

<style lang="scss" scoped>
van-tabbar {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.active_tab img {
  width: 24px;
  height: 24px;
}

van-tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
van-tabbar-item span {
  font-size: 14px;
}
</style>